package com.shakespace.artofandroid

import android.app.Activity
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.shakespace.artofandroid.chapter01.Chapter01Activity
import com.shakespace.artofandroid.chapter02.Chapter2Activity
import com.shakespace.artofandroid.chapter03.ViewActivity
import com.shakespace.artofandroid.chapter05remoteview.RemoteViewActivity
import com.shakespace.artofandroid.chapter06drawable.DrawableActivity
import com.shakespace.artofandroid.chapter07anim.AnimActivity
import com.shakespace.artofandroid.chapter08window.WindowActivity
import com.shakespace.artofandroid.chapter12bitmapandcache.GalleryActivity
import com.shakespace.firstlinecode.global.start
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        initListener()
    }

    private fun initListener() {

        tv_chapter01.setOnClickListener {
            start(Chapter01Activity::class.java)
        }
        tv_chapter02.onClick(Chapter2Activity::class.java)
        tv_chapter03.onClick(ViewActivity::class.java)

        tv_chapter05.onClick(RemoteViewActivity::class.java)
        tv_chapter06.onClick(DrawableActivity::class.java)
        tv_chapter07.onClick(AnimActivity::class.java)
        tv_chapter08.onClick(WindowActivity::class.java)
        tv_chapter12.onClick(GalleryActivity::class.java)
    }


    private fun View.onClick(clazz: Class<out Activity>) {
        setOnClickListener {
            start(clazz)
        }
    }
}
